package listbyorder.access201_300.test279;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/27 13:03
 */
public class Solution3 {
    // 300栈回溯
    public int numSquares(int n) {
        return numSquaresHelper(n);
    }

    private int numSquaresHelper(int n) {
        if (n == 0) return 0;
        int count = Integer.MAX_VALUE;
        for (int i = 1; i * i <= n; i++) {
            count = Math.min(count, numSquaresHelper(n - i * i) + 1);
        }
        return count;
    }
}
